const app = getApp();
const log = require('../../log.js');
const util = require('../../util.js');
const tabService = require("../../libs/tabService");
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that=this;   
        console.log('--------options----')
        console.log(options);
        console.log('--------options----')
        var parent_id=options.parent_id;
        var store_id=options.id;
        var sn=options.sn;
        if(store_id!=undefined){
          console.log('store_id1=>'+store_id)
          this.setData({
            store_id:store_id
          });
          wx.setStorageSync('store_id',store_id);
      }else{
        store_id=options.store_id;
        if(store_id==undefined){
            store_id=wx.getStorageSync('store_id');
        }
        wx.setStorageSync('store_id',store_id);
        console.log('store_id2=>'+store_id)
            this.setData({
              store_id:store_id
            });
        
        

        
      }
    if(parent_id!=undefined){
            this.setData({
                parent_id:parent_id
              })
              wx.setStorageSync('parent_id',parent_id);
        }else{
            parent_id = wx.getStorageSync('parent_id');
        
        }
         var open=wx.getStorageSync('open'); 
         that.setData({
            platform:app.globalData.platform,    
            open:open,
            width:app.globalData.windowWidth,
            height:app.globalData.windowHeight,
            statusBarHeight:app.globalData.statusBarHeight,
            navHeight:app.globalData.navHeight,
            marginTop:app.globalData.navTitleTop,
            domain:app.globalData.platUrl
          })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      /*
        var role=1
        wx.setStorageSync('role',role);    
        this.update(role)    
        tabService.updateIndex(this, 2);
        */
        this.getOct();
      },
      update(role) {
        tabService.updateRole(this, role);
      },
      goBack:function(){
        wx.navigateBack();
      },
   getOct:function(){
        let that = this;
        var open=wx.getStorageSync('open');
        wx.request({
            url: app.globalData.platUrl+'lottery/oct',
            data:{from:1,user_id:open.user_id},
            success:res=>{
                console.log(res);
                var data=res.data;
                var len=data.codeList.length;
                if(len>5){
                  len=5;
                }
                if(res.statusCode==200){
                    that.setData({
                       list1:data.list1,
                       list2:data.list2, 
                       list3:data.list3, 
                       list4:data.list4,
                       list5:data.list5,
                       list6:data.list6, 
                       list7:data.list7,
                       codeList:data.codeList,
                       swiperlenght:len,
                       imgList:data.imgList,
                       shareTitle:data.shareTitle,
                       shareLogo:data.shareLogo,
                       shareIndex:data.shareIndex,

                     
                    })
                   
                }
            }
        })
    },
    swiperChange:function(e){
      // console.log(e.detail.current);
         this.setData({
             nowIdx: e.detail.current
         })
     },
    imageLoad(e){
      var width=this.data.width+2;
      console.log(e);
      var h=((width/e.detail.width)*e.detail.height+16)/2;
     
     
     
    
      console.log(h);
      this.setData({
         marginTop:h,
     
      })
     // console.log(this.data.width);
  },
    goto:function(e){
        console.log(e);
        var url=e.currentTarget.dataset.url;
        var parent_id=wx.getStorageSync('parent_id');
        var index=e.currentTarget.dataset.index;
        if(url=="#"){

        }else if(url=='phone'){
            wx.makePhoneCall({
              phoneNumber: '400-800-2177',
            })
        }else if(url=='coupon'){
            var date=util.formatTime(new Date());
            var face_value=e.currentTarget.dataset.face_value;
            var pay_money=e.currentTarget.dataset.pay_money;
            var yxq=e.currentTarget.dataset.yxq;
            var month=e.currentTarget.dataset.month;
             log.info("Time:"+date+",page:index,function:goto:,index"+index);
            this.getCoupon(face_value,month,yxq,pay_money);
        }else{
            if(index=='index'){
                wx.reLaunch({
                    url: url,
                  })
            }else{
                console.log(url);
                wx.navigateTo({
                    url: url,
                  })
            }
       
        }
      // console.log(url);
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage(e) {
      var open=wx.getStorageSync('open');
      var parent_id=open.user_id;
      var that = this;
      var title=this.data.shareTitle;
      var shareIndex=this.data.shareIndex;
      var store_id=wx.getStorageSync('store_id');
 　　var shareObj = {
 　　　　title: title,    
 　　　　path: '/pages/index/index?parent_id='+parent_id+'&store_id'+store_id,  
 　　　　imageUrl: shareIndex 
 　　　
 　　}
 　　// 来自页面内的按钮的转发
 　　if( e.from == 'button' ){
   　　　shareObj.title=title;
 　　　　shareObj.path = '/pages/index/index?parent_id='+parent_id+'&store_id'+store_id;
 　　}
 console.log(shareObj);
 　　// 返回shareObj
 　　return shareObj;
  }
})